//学科评估
<template>
  <div class="module_">
    <div class="mb8">
      <search @clearSearch='clearSearch'>
        <el-form label-width='80px' inline autocomplete="off" :model="pageparm" class="search_box">
          <!-- <el-form-item label="科室">
            <inputSearch ref="search_d" @onChange='searchChane($event,"departments_id")'  />
          </el-form-item> -->
          <el-form-item label="评估年度">
            <el-date-picker size="medium" v-model="pageparm.year" type="year" format="yyyy" value-format="yyyy"
              @change="searchChane($event,'year')" placeholder="请选择年份搜索">
            </el-date-picker>
          </el-form-item>
        </el-form>
        <template slot="footer">
          <el-button v-permission="{action:'发布评估添加',effect:'delete'}" size="medium" type="primary"
            @click="editFormVisible = true">发布评估</el-button>
        </template>
      </search>
    </div>
    <el-table :data="tableData" class="flex-1" height="100%" size="medium" border highlight-current-row
      v-loading="tableLoading" stripe @sort-change="tableSortChange">
      <el-table-column align="center" show-overflow-tooltip prop="year" label="评估年度" width="200" sortable="custom">
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="publisher" label="发布人" width="200" sortable="custom">
        <template slot-scope="scope">
          {{scope.row.employee?scope.row.employee.name:''}}
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="created_at" label="发布时间" width="200"
        sortable="custom">
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="end_time" label="截止时间" width="200" sortable="custom">
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="status" label="状态" width="200" sortable="custom">
        <template slot-scope="scope">
          {{statusObj[scope.row.status]}}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="120">
        <div slot-scope="scope" class="flex-justify-end">
          <el-tooltip effect="dark" content="去评分" placement="bottom-end">
            <el-button v-if="scope.row.edit && scope.row.status == 1" size="small" @click="goStart(scope.row,1)"
              icon="el-icon-star-off f-12" circle></el-button>
          </el-tooltip>
          <el-tooltip effect="dark" content="查看打分记录" placement="bottom-end">
            <el-button v-if="scope.row.edit" size="small" @click="goStart(scope.row,2)" icon="el-icon-s-claim f-14"
              circle></el-button>
          </el-tooltip>
          <el-tooltip v-if="scope.row.status == 1 && adminShow" effect="dark" content="删除" placement="bottom-end">
            <el-popconfirm class="ml8" title="确定删除该模板吗？" @confirm="deleteUser(scope.row)">
              <el-button slot="reference" size="small" type="danger"
                icon="el-icon-delete" circle></el-button>
            </el-popconfirm>
          </el-tooltip>
          <el-tooltip v-if="scope.row.status == 2 && adminShow" effect="dark" content="公布打分结果" placement="bottom-end">
            <el-popconfirm class="ml8" title="确定公布打分结果吗？" @confirm="release(scope.row)">
              <el-button  slot="reference" size="small" type="success" circle
                icon="el-icon-s-promotion">
              </el-button>
            </el-popconfirm>
          </el-tooltip>
        </div>
      </el-table-column>
    </el-table>

    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

    <el-dialog :visible.sync="editFormVisible" width="500px" @close='dialogClose' :close-on-click-modal='false'
      :close-on-press-escape='false'>
      <h2 slot="title" class="tx-c">发布评估</h2>
      <el-form autocomplete="off" label-width="100px" class="form">
        <el-form-item label="评估年份" class="tip">
          <el-date-picker size="medium" v-model="editForm.year" type="year" format="yyyy" value-format="yyyy"
            placeholder="请选择年份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="截止日期" class="tip">
          <el-date-picker size="medium" v-model="editForm.end_time" type="date" format="yyyy-MM-dd"
            value-format="yyyy-MM-dd" placeholder="请选择截止日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="临床学科">
          <div class="item_content flex-align-center">
            <multipleSearch ref="multipleSearch_0" @onChange="choseKeShi($event,1)" :disabled="chosekeShi[0]"
              class="multipleSearch" type="keshi" :options="{type:1}" />
            <el-checkbox v-model="chosekeShi[0]" border size="medium" class="ml8" @change="selectAll($event,0)">全选
            </el-checkbox>
          </div>
        </el-form-item>
        <el-form-item label="医技学科">
          <div class="item_content flex-align-center">
            <multipleSearch ref="multipleSearch_1" @onChange="choseKeShi($event,2)" :disabled="chosekeShi[1]"
              class="multipleSearch" type="keshi" :options="{type:2}" />
            <el-checkbox v-model="chosekeShi[1]" border size="medium" class="ml8" @change="selectAll($event,1)">全选
            </el-checkbox>
          </div>
        </el-form-item>
        <!-- <el-form-item label="职能学科">
          <div class="item_content flex-align-center">
            <multipleSearch ref="multipleSearch_2" @onChange="choseKeShi($event,3)" :disabled="chosekeShi[2]"
              class="multipleSearch" type="keshi" :options="{type:3}" />
            <el-checkbox v-model="chosekeShi[2]" border size="medium" class="ml8" @change="selectAll($event,2)">全选
            </el-checkbox>
          </div>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="flex-justify-bcenter">
        <el-button @click="editFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit" :loading='btnLoading'>确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    Apievaluatetask,
    ApievaluatetaskAdd,
    Apievaluatetaskdel,
    ApievaluatetaskPut
  } from '@/api'
  import {
    debounce,
    adminShow,
    throttle
  } from "@/utils/index";
  // import {judge} from '../js/assess.js'
  import multipleSearch from '@/components/multipleSearch'
  export default {
    name: 'subject_release',
    components: {
      multipleSearch
    },
    data() {
      return {
        adminShow: adminShow(),
        tableData: [],
        editFormVisible: false,
        editForm: {
          year: '',
          1: [],
          2: [],
          3: [],
          all1: false,
          all2: false,
          all3: false,
          end_time: null
        }, //修改或者查看详情

        pageparm: {
          page: 1,
          perPage: 20,
          total: null,
          sort_str: null,
          sort_order: 'desc',
        },
        tableLoading: false,

        btnLoading: false,

        dialogTitle: '',

        statusObj: {
          1: '评估进行中',
          2: '评估已结束',
          3: '已公布'
        },
        viewScore: false,

        chosekeShi: [false, false, false],

        pickerOptions: {
          disabledDate: (time) => {
            return time.getTime() < Date.now() - 86400000;
          }
        }
      }
    },
    mounted() {
      this.getList()
    },
    methods: {
      release(item) {
        ApievaluatetaskPut(item.id, {
          status: 3
        }).then(() => {
          this.$message.success('公布成功');
          this.getList()
        }).catch(() => {
          this.$message.error('公布失败');
        })
      },
      deleteUser(item) {
        Apievaluatetaskdel(item.id).then(() => {
          this.$message.success('删除成功');
          this.getList()
        }).catch(() => {
          this.$message.error('删除失败');
        })
      },
      choseKeShi(arr, i) {
        this.editForm[i] = arr
      },
      selectAll(flag, i) {
        this.editForm['all' + (i + 1)] = flag
        this.editForm[i + 1] = []
        this.$refs['multipleSearch_' + i].clear()
      },
      goStart(value, i) {
        if (i === 1) this.$router.push('/subject/assess?year=' + value.year + '&id=' + value.id + '&template_id=' + value.template_id)
        else this.$router.push('/subject/viewResult?year=' + value.year + '&id=' + value.id + '&template_id=' + value.template_id)
      },
      tableSortChange(column) {
        if (column.order === "descending") {
          this.pageparm.sort_str = column.prop;
          this.pageparm.sort_order = "desc";
        } else if (column.order === "ascending") {
          this.pageparm.sort_str = column.prop;
          this.pageparm.sort_order = "asc";
        } else {
          this.pageparm.sort_str = null;
          this.pageparm.sort_order = null;
        }
        this.getList()
      },
      //搜索
      clearSearch() {
        // this.$refs.search_d.clear()
      },
      searchChane(i, val) {
        this.pageparm[val] = i
        this.pageparm.page = 1
        this.getList()
      },
      //分页
      callFather(pageparm) {
        this.pageparm.page = pageparm.page
        this.pageparm.perPage = pageparm.perPage
        this.getList()
      },
      getList() {
        this.tableLoading = true
        Apievaluatetask(this.pageparm).then(({
          data,
          page
        }) => {
          this.tableData = data || []
          this.pageparm.total = page.total
          this.tableLoading = false
        }).catch(() => {
          this.tableLoading = false
        })
      },
      dialogClose() {
        this.editForm = {
          year: '',
          1: [],
          2: [],
          3: [],
          all1: false,
          all2: false,
          all3: false,
          end_time: null
        }
        this.chosekeShi = [false, false, false]
        this.$refs.multipleSearch_0.clear()
        this.$refs.multipleSearch_1.clear()
        // this.$refs.multipleSearch_2.clear()
      },
      submit: debounce(function () { //提交  修改或新增
        const options = this.editForm
        if (!options.year) {
          this.$message({
            type: 'error',
            message: '请先选择年份！'
          });
          return
        }
        if (!options.end_time) {
          this.$message({
            type: 'error',
            message: '请先选截至日期！'
          });
          return
        }
        if (options[1].length === 0 && options[2].length === 0 && options[3].length === 0 && options.all1 ===
          false && options.all2 === false && options.all3 === false) {
          this.$message({
            type: 'error',
            message: '必须选择一个科室！'
          });
          return
        }

        this.btnLoading = true
        options.publisher = this.$store.state.userInfo.employees_id
        ApievaluatetaskAdd(options).then(res => {
          this.$message({
            type: 'success',
            message: '添加成功!'
          });
          this.editFormVisible = false
          this.getList()
        }).catch(() => {
          this.$message({
            type: 'error',
            message: '添加失败!'
          });
        }).finally(() => {
          this.btnLoading = false
        });
      }, 800, true)
    },

  }
</script>
<style lang='less' scoped>
</style>